package com.chinalife

import org.junit.Test
import org.junit.runner.RunWith
import groovy.sql.Sql
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

import com.chinalife.repository.UserDao
import com.fasterxml.jackson.annotation.JsonFormat.Value

@RunWith(SpringRunner)
@SpringBootTest
class SpringGroovyApplicationTests {

	@Autowired
	UserDao dao
	
	
	@Test
	void contextLoads() {
		for(i in 0..100){
			def map = [id: i+10000, userName: "wanger${i}", password: "123456", birthday: new Date()]
			dao.add(map)
		}
	}
	
	@Test
	void testFindList() {
		dao.findList(1, 100).each{
			it.each{key, value ->
				println "${key}: ${value}"
			}
		}
	}
	
	/**
	 * groovy原生sql 
	 */
	@Test
	void testGdbc(){
		def sql = Sql.newInstance("jdbc:mysql://127.0.0.1:3306/Test?useUnicode=true&autoReconnect=true&useOldAliasMetadataBehavior=true&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false", "root", "123123", "com.mysql.jdbc.Driver")
		for(i in 0..100){
			def id = 10101+i
			def userName = "wangda"
			println userName
			def password = "123456"
			def birthday = new Date()
			sql.execute("insert into T_USER(id, userName, password, birthday) values(${id}, ${userName}, ${password}, ${birthday})")
		}
	}

}
